package com.xp.tinyurl.admin.auth;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: TODO
 * @Author: xiaoche
 * @Date: 2022/11/3 07:53
 */
@Data
@ConfigurationProperties(prefix = "audience")
@Component
public class AudienceConf {
    private List<Config> configs;

    @Data
    public static class Config {
        private String name;
        private String secret;
        private Integer expireType;
        private Integer expireTime;
    }

    public static Config buildAudience(AudienceConf audience, String name) {
        List<Config> configs = audience.getConfigs();
        for (Config config : configs) {
            if (config.getName().equals(name)) {
                return config;
            }
        }
        return null;
    }
}
